{extend name="layout/iframe" /}

{block name="pagecss"}
<style>
    .layui-form-select .layui-input{
        padding-right: 0;
        cursor: pointer;
    }
</style>
{/block}

{block name="content"}
<div class="layui-card-body layui-layout-admin" style="padding: 15px;">
    <form class="layui-form" action="" lay-filter="component-form-group">
        <div class="layui-row layui-col-xs12">
            <div class="layui-col-md9 layui-col-xs6">
                <div class="layui-form-item magt3">
                    <label class="layui-form-label"><span class="required">*</span>是否启用</label>
                    <div class="layui-input-inline">
                        <input type="checkbox" name="status" {if condition="($info.status == 1)"}checked=""{/if} lay-skin="switch" lay-text="启用|禁用"><div class="layui-unselect layui-form-switch" lay-skin="_switch"><em>启用</em><i></i></div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="required">*</span>条码</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="bar_code" value="{$info.bar_code}" lay-verify="required" placeholder="" autocomplete="off" readonly>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="required">*</span>商品名</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="name" name="name" value="{$info.name}" data-name="{$info.name}" maxlength="40" lay-verify="name" placeholder="" autocomplete="off">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3 layui-col-xs4">
                <div id="view-img_urls">
                    <div class="layui-upload-list thumbBox mag0 magt3">
                        <input type="hidden" class="layui-input" name="ori_img_url" value="{$info.img_url}">
                        <input type="hidden" class="layui-input img_url" name="img_url" value="{$info.img_url}" lay-verify="img_url">
                        <input type="hidden" class="layui-input img_urls" name="img_urls" value="{$info.img_urls}">
                        <img class="layui-upload-img thumbImg default_upload" src="{$info.img_url}">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="required">*</span>是否是赠品</label>
            <div class="layui-input-block is_gift">
                <input type="radio" name="is_gift" value="1" title="是" {if condition="($info.is_gift == 1)"}checked=""{/if}>
                <div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon"></i><div>是</div></div>
                <input type="radio" name="is_gift" value="2" title="否" {if condition="($info.is_gift == 2)"}checked=""{/if}>
                <div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div>否</div></div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><span class="required">*</span>分类</label>
                <div class="layui-input-block">
                    <select name="category_id" lay-verify="required">
                        <option value="">请选择</option>
                        {foreach name="categorys" item="category"}
                            <option value="{$category.id}" {if condition="($info.category_id == $category.id)"}selected=""{/if}>{$category.name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"><span class="required">*</span>单位</label>
                <div class="layui-input-block">
                    <select name="unit" lay-verify="required">
                        <option value="">请选择</option>
                        {foreach name="unitList" item="unit" key="unitKey"}
                            <option value="{$unitKey}" {if condition="($info.unit == $unitKey)"}selected=""{/if}>{$unit}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><span class="required">*</span>售价</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="price" value="{$info.price / 100}" maxlength="10" lay-verify="price" placeholder="" autocomplete="off">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"><!--<span class="required">*</span>-->进价</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="purchase_price" value="{$info.purchase_price / 100}" maxlength="10" lay-verify="purchase_price" placeholder="" autocomplete="off">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><!--<span class="required">*</span>-->批发价</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="wholesale_price" value="{$info.wholesale_price / 100}" maxlength="10" lay-verify="wholesale_price" placeholder="" autocomplete="off">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"><span class="required">*</span>最低售价</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="lowest_price" value="{$info.lowest_price / 100}" maxlength="10" lay-verify="lowest_price" placeholder="" autocomplete="off">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><span class="required">*</span>计价方式</label>
                <div class="layui-input-block">
                    <select class="price_type" name="price_type" lay-verify="required">
                        <option value="">请选择</option>
                        <option value="1" {if condition="($info.price_type == 1)"}selected=""{/if}>普通</option>
                        <option value="2" {if condition="($info.price_type == 2)"}selected=""{/if}>称重</option>
                        <option value="3" {if condition="($info.price_type == 3)"}selected=""{/if}>计数</option>
                    </select>
                </div>
            </div>
            <!--<div class="layui-inline">
                <label class="layui-form-label">会员积分</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="member_integral" value="{$info.member_integral}" maxlength="10" lay-verify="member_integral" placeholder="" autocomplete="off">
                </div>
            </div>-->
            <input type="hidden" class="layui-input" name="member_integral" value="{$info.member_integral}" maxlength="10" lay-verify="member_integral" autocomplete="off">
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><!--<span class="required">*</span>-->生鲜码</label>
                <div class="layui-input-inline" style="width: 40%;">
                    <input type="text" class="layui-input" name="fresh_code" value="{$info.fresh_code}" maxlength="5" lay-verify="fresh_code" placeholder="" autocomplete="off">
                </div>
                <button type="button" class="layui-btn fresh_code-btn" style="margin-left: -10px;">生成</button>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"><!--<span class="required">*</span>-->PLU码</label>
                <div class="layui-input-inline" style="width: 40%;">
                    <input type="text" class="layui-input" name="plu_code" value="{$info.plu_code}" maxlength="4" lay-verify="plu_code" placeholder="" autocomplete="off">
                </div>
                <button type="button" class="layui-btn plu_code-btn" style="margin-left: -10px;">生成</button>
            </div>
        </div>
        <div class="layui-form-item">
            <!--<div class="layui-inline">-->
                <!--<label class="layui-form-label">初始库存</label>-->
                <!--<div class="layui-input-block">-->
                    <!--<input type="number" class="layui-input" name="store_count" value="{$info.store_count}" maxlength="10" lay-verify="store_count" placeholder="" autocomplete="off">-->
                <!--</div>-->
            <!--</div>-->
            <div class="layui-inline">
                <label class="layui-form-label"><span class="required">*</span>库存上限</label>
                <div class="layui-input-block">
                    <input type="number" class="layui-input" name="upper_store_count" value="{$info.upper_store_count}" maxlength="10" lay-verify="upper_store_count" placeholder="" autocomplete="off">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"><span class="required">*</span>库存下限</label>
                <div class="layui-input-block">
                    <input type="number" class="layui-input" name="lower_store_count" value="{$info.lower_store_count}" maxlength="10" lay-verify="lower_store_count" placeholder="" autocomplete="off">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">退款</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="after_sale_type" {if condition="($info.after_sale_type == 1)"}checked=""{/if} lay-skin="switch" lay-text="启用|禁用"><div class="layui-unselect layui-form-switch layui-form-onswitch" lay-skin="_switch"><em>启用</em><i></i></div>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">退款退货</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="is_returned" {if condition="($info.is_returned == 1)"}checked=""{/if} lay-skin="switch" lay-text="启用|禁用"><div class="layui-unselect layui-form-switch layui-form-onswitch" lay-skin="_switch"><em>启用</em><i></i></div>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="required">*</span>销售方式</label>
            <div class="layui-input-block">
                <input type="checkbox" class="sales_way" name="sales_way[]" lay-skin="primary" title="实体店" value="1" {if condition="(in_array(1, $info.sales_way))"}checked=""{/if}>
                <div class="layui-unselect layui-form-checkbox" lay-skin="primary">
                    <span>实体店</span><i class="layui-icon layui-icon-ok"></i>
                </div>
                <input type="checkbox" class="sales_way" name="sales_way[]" lay-skin="primary" title="线上网点" value="2" {if condition="(in_array(2, $info.sales_way))"}checked=""{/if}>
                <div class="layui-unselect layui-form-checkbox" lay-skin="primary">
                    <span>线上网点</span><i class="layui-icon layui-icon-ok"></i>
                </div>
            </div>
        </div>
        <!--<div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="required">*</span>快递运费</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="freight_template_id" lay-verify="required" placeholder="" autocomplete="off">
            </div>
        </div>-->
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">商品规格</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="spec" value="{$info.spec}" maxlength="40" placeholder="" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="required">*</span>供货商</label>
            <div class="layui-input-block">
                <select name="supplier_id" lay-verify="required">
                    <option value="">请选择</option>
                    {foreach name="suppliers" item="supplier"}
                        <option value="{$supplier.id}" {if condition="($info.supplier_id == $supplier.id)"}selected=""{/if}>{$supplier.name}</option>
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">商品品牌</label>
            <div class="layui-input-block">
                <select name="brand_id">
                    <option value="">请选择</option>
                    {foreach name="brands" item="brand" key="brandKey"}
                        <option value="{$brand.id}" {if condition="($info.brand_id == $brand.id)"}selected=""{/if}>{$brand.name}</option>
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><!--<span class="required">*</span>-->重量</label>
                <div class="layui-input-block">
                    <input type="number" class="layui-input" name="weight" value="{$info.weight}" maxlength="10" lay-verify="weight" placeholder="克" autocomplete="off">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">包装</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="packing" value="{$info.packing}" maxlength="40" placeholder="" autocomplete="off">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">产地</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="address" value="{$info.address}" maxlength="60" placeholder="" autocomplete="off">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">保质期</label>
                <div class="layui-input-block">
                    <input type="number" class="layui-input" name="quality_time" value="{$info.quality_time}" maxlength="10" lay-verify="quality_time" placeholder="天" autocomplete="off">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">贮存方式</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="storage_mode" value="{$info.storage_mode}" maxlength="20" placeholder="" autocomplete="off">
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">商品描述</label>
            <div class="layui-input-block">
                <!--<textarea name="describe" placeholder="请输入内容" class="layui-textarea"></textarea>-->
                <input type="text" class="layui-input" name="describe" value="{$info.describe}" maxlength="100" placeholder="" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">安心检测</label>
            <div class="layui-input-block">
                <input type="hidden" class="layui-input detections" name="detections" value="{$info.detections}" autocomplete="off">
                <button type="button" class="layui-btn layui-btn-primary view-detections" style="float: right;"><i class="layui-icon">&#xe654;</i> 上传检测报告</button>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">适合菜谱</label>
            <div class="layui-input-block">
                <input type="hidden" class="layui-input cookbook_ids" name="cookbook_ids" value="{$info.cookbook_ids}" autocomplete="off">
                <button type="button" class="layui-btn layui-btn-primary view-cookbook" style="float: right;"><i class="layui-icon">&#xe654;</i> 新增菜谱</button>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">商品详情</label>
            <div class="layui-input-block">
                <div id="upload-image">
                    {foreach name="detailImgs" item="detailImg"}
                        <span class="multi-image">
                            <input type="hidden" name="img_ids" value="{$detailImg.id}">
                            <input type="hidden" name="detail_imgs[]" value="{$detailImg.img_url}">
                            <img class="exist-image" src="{$detailImg.img_url}" alt="" />
                            <img class="del" src="__STATIC__/admin/pages/image/del.png" alt="">
                        </span>
                    {/foreach}
                    <span id="upload-btn" data-multi="true" data-ajax="true" data-field="detail_imgs">
                        <img class="load_img" src="__STATIC__/admin/img/default.png" alt="图片上传" style="width: 100px;height: 100px;" />
                        <!--<div class="uploader-div">
                            <span class="icon">+</span>
                            <small>上传图片</small>
                        </div>-->
                    </span>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">商品视频</label>
            <div class="layui-input-block">
                <div id="upload-video" class="v_center h flex_wrap">
                    {foreach name="videos" item="video"}
                        <span class="multi-image">
                            <input type="hidden" name="video_ids" value="{$video.id}">
                            <input type="hidden" name="videos[]" value="{$video.img_url}">
                            <video class="img-responsive" name="img_qiniu_url" src="{$video.img_url}">
                                <source name="img_qiniu_url"  class="img-responsive" src="{$video.img_url}"  type="video/mp4" />
                            </video>
                            <img class="del" src="__STATIC__/admin/pages/image/del.png" alt="">
                        </span>
                    {/foreach}
                    <span id="upload-video-btn" data-multi="true" data-ajax="true" data-field="detail_imgs">
                        <img class="load_img" src="__STATIC__/admin/img/default.png" alt="图片上传" style="width: 100px;height: 100px;" />
                    </span>
                </div>
            </div>
        </div>

        <input type="hidden" name="id" value="{$info.id}">
        <input type="hidden" class="layui-input" name="ori_qr_code" value="{$info.qr_code}">

        <div class="layui-form-item layui-row layui-col-xs12">
            <div class="layui-input-block">
                <div class="layui-footer" style="z-index: 2;">
                    <!--<button type="button" class="layui-btn layui-btn-primary" onclick="history.go(-1);">返回 <i class="layui-icon">&#xe65c;</i></button>-->
                    <!--<button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
                    <button type="button" class="layui-btn layui-btn-primary close-btn">取消</button>
                    <button type="button" class="layui-btn" lay-submit="" lay-filter="laySave">保存 <i class="layui-icon">&#xe609;</i></button>
                </div>
            </div>
        </div>
    </form>
</div>

<input type="hidden" class="save_url" value="{:url('admin/'.strtolower($model).'/savepost')}">
<input type="hidden" class="check_name_url" value="{:url('admin/'.strtolower($model).'/checkName')}">

<input type="hidden" class="img_urls_url" value="{:url('admin/product/getimgurls')}">
<input type="hidden" class="detections_url" value="{:url('admin/product/getdetections')}">
<!--<input type="hidden" class="cookbooks_url" value="{:url('admin/cookbook/index')}">-->
<input type="hidden" class="cookbooks_url" value="{:url('admin/product/getcookbooks')}">
<input type="hidden" class="cerate_bar_code_url" value="{:url('admin/product/cerateBarcode')}">
<input type="hidden" class="cerate_fresh_code_url" value="{:url('admin/product/cerateFreshcode')}">
<input type="hidden" class="cerate_plu_code_url" value="{:url('admin/product/ceratePlucode')}">
{/block}

{block name="pagescript"}
<script src="__STATIC__/admin/js/qiniu/plupload.full.min.js" type="text/javascript"></script>
<script src="__STATIC__/admin/js/qiniu/qiniu.js" type="text/javascript"></script>
<script src="__STATIC__/admin/js/qiniu/qiniuConfig.js" type="text/javascript"></script>

<script src="__STATIC__/admin/pages/js/uploadfile1.js" type="text/javascript"></script>
<script src="__STATIC__/admin/pages/js/product.js" type="text/javascript"></script>
{/block}